if not ( RES_DISTRIB == 2 ) then Error("Please Install Resource Distribution 2 Addon.'" ) return end

TOOL.Category = 'Shuttle'
TOOL.Name = '#Shuttle Systems'
TOOL.Command = nil
TOOL.ConfigName = ''
if (CLIENT and GetConVarNumber("RD_UseLSTab") == 1) then TOOL.Tab = "Fallen Menu" end

TOOL.ClientConVar['type'] = 'water_scrubber'
TOOL.ClientConVar['model'] = 'models/props_wasteland/laundry_washer003.mdl'

cleanup.Register('energysystem')

if ( CLIENT ) then
	language.Add( 'Tool_shuttleenergysystems_name', 'Life Support Generators' )
	language.Add( 'Tool_shuttleenergysystems_desc', 'Create Generators attached to any surface.' )
	language.Add( 'Tool_shuttleenergysystems_0', 'Left-Click: Spawn a Device.  Right-Click: Repair Device.' )

	language.Add( 'Undone_shuttleenergysystems', 'Generator Undone' )
	language.Add( 'Cleanup_shuttleenergysystems', 'LS: Generators' )
	language.Add( 'Cleaned_shuttleenergysystems', 'Cleaned up all Life Support Generators' )
	language.Add( 'SBoxLimit_shuttleenergysystems', 'Maximum Life Support Generators Reached' )
end

local shuttleenergysystems = {}
if (SERVER) then
	shuttleenergysystems.naquadah_mine = function( ply, ent, system_type, system_class, model )
		local maxhealth = 8000
		local mass = 55000
		RD_AddResource(ent, "Raw Naquadah", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end
	
	shuttleenergysystems.naquadah_refinery = function( ply, ent, system_type, system_class, model )
		local maxhealth = 800
		local mass = 55000
		RD_AddResource(ent, "Refined Naquadah", 0)
		RD_AddResource(ent, "Raw Naquadah", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end
	
	shuttleenergysystems.naquadah_generator = function( ply, ent, system_type, system_class, model )
		local rtable = {}
		local maxhealth = 120
		local mass = 50
		rtable.radius = 175
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "Refined Naquadah", 0)
		LS_RegisterEnt(ent, "Generator")
		return rtable, maxhealth, mass
	end
	
	shuttleenergysystems.water_scrubber = function( ply, ent, system_type, system_class, model )
		local rtable = {}
		local maxhealth = 100
		local mass = 10
		rtable.radius = 175
		RD_AddResource(ent, "water", 0)
		RD_AddResource(ent, "energy", 0)
		LS_RegisterEnt(ent, "Generator")
		return rtable, maxhealth, mass
	end
	
	shuttleenergysystems.water_air_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 600
		local mass = 20
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "water", 0)
		RD_AddResource(ent, "air", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end
end

	shuttleenergysystems.naquadah_storage_cache = function( ply, ent, system_type, system_class, model )
		local rtable, maxhealth, mass = {}, 0, 0
		if (model == "models/props_c17/substation_transformer01a.mdl") then
			maxhealth = 2400
			mass = 200000
			RD_AddResource(ent, "Raw Naquadah", 30000)
			RD_AddResource(ent, "Refined Naquadah", 30000)
			RD_AddResource(ent, "water", 30000)
			RD_AddResource(ent, "air", 30000)
			RD_AddResource(ent, "energy", 30000)
			RD_AddResource(ent, "coolant", 30000)
		end
		LS_RegisterEnt(ent, "Storage")
		return rtable, maxhealth, mass
	end

local energysystem_models = {
	{ '1. Naquadah Mine', 'models/props_wasteland/rockcliff05a.mdl', 'naquadah_mine' },
	{ '2. Naquadah Refinery', 'models/naquada-reactor.mdl', 'naquadah_refinery' },
	{ '3. Naquadah Generator', 'models/naquada-reactor.mdl', 'naquadah_generator' },
	{ '4. Water Scrubber', 'models/props_c17/light_decklight01_off.mdl', 'water_scrubber' },
	{ '5. Water Air Extractor - LS2', 'models/naquada-reactor.mdl', 'water_air_extractor' },
	{ '6. Naquadah Resource Cache', 'models/props_c17/substation_transformer01a.mdl', 'naquadah_storage_cache' }
}

RD2_ToolRegister( TOOL, energysystem_models, nil, "shuttleenergysystems", 30, shuttleenergysystems )
